package com.gzx.plugin.tjzy.modular.call.predict.mapper;

import com.gzx.plugin.tjzy.modular.call.predict.entity.GzxPredictCall;
import com.gzx.plugin.tjzy.modular.call.predict.vo.GzxPredictAllVo;
import com.gzx.plugin.tjzy.modular.call.predict.vo.GzxPredictCallVo;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import vip.xiaonuo.common.mapper.BaseMapperPlus;

import java.util.List;

/**
 * @author zjt
 * @description
 * @since 2025/3/27 17:20
 */
public interface GzxPredictCallMapper extends BaseMapperPlus<GzxPredictCall, GzxPredictCallVo> {

    @Update("<script>" +
            "UPDATE gzx_predict_call a " +
            "LEFT JOIN (" +
            "    SELECT task_id, COUNT(1) AS completedCount " +
            "    FROM gzx_ht_call_receipt_business " +
            "    WHERE task_id IN " +
            "    <foreach item='taskId' collection='taskIdSet' open='(' separator=',' close=')'>" +
            "        #{taskId}" +
            "    </foreach>" +
            "    GROUP BY task_id " +
            ") b ON a.task_id = b.task_id " +
            "SET a.completed_count = IFNULL(b.completedCount, 0), " +
            "a.batch_status = IF(a.completed_count >= a.total_count, 3, a.batch_status)," +
            "update_time = now() " +
            "WHERE a.task_id IN " +
            "<foreach item='taskId' collection='taskIdSet' open='(' separator=',' close=')'>" +
            "   #{taskId}" +
            "</foreach>" +
            "</script>")
    void modifyBatchStatusAndCount(List<String> taskIdSet);

    //获取当天的线路信息
    @Select({
            "<script>",
            "select caller,call_name as callName from gzx_predict_call " +
                    "where create_time like concat(#{currentMonth,jdbcType=VARCHAR},'%') " +
                    "</script>"
    })
    List<GzxPredictAllVo> getCallerInfo(String currentMonth);
}
